<?php
class Photo {
	function add_profile_photo($photo_name) {
		$user_id = $_SESSION['auth'];
		include("inc_/sup3rs3cr3tt3xt4m3t0kn0vv.php");
		$mysqli = new mysqli($host, $user, $password, $database);
		if(mysqli_connect_errno()) {
			printf("Connect failed: %s\n", mysqli_connect_error());
			exit();
		}
		$sql = "UPDATE users SET user_photo_file='$photo_name' WHERE user_id='$user_id'";
		$mysqli->query($sql);
	}
	
	function add_place_photo($photo_name, $place_id, $date) {
		$user_id = $_SESSION['auth'];
		include("inc_/sup3rs3cr3tt3xt4m3t0kn0vv.php");
		$mysqli = new mysqli($host, $user, $password, $database);
		if(mysqli_connect_errno()) {
			printf("Connect failed: %s\n", mysqli_connect_error());
			exit();
		}
		$sql = "INSERT INTO place_photo(place_id, photo_file, photo_date_time) VALUES('$place_id', '$photo_name', '$date')";
		$mysqli->query($sql);
		$id = $mysqli->insert_id;
		return $id;
	}
	
	function get_place_photos($place_id) {
		include("inc_/sup3rs3cr3tt3xt4m3t0kn0vv.php");
		$mysqli = new mysqli($host, $user, $password, $database);
		if(mysqli_connect_errno()) {
			printf("Connect failed: %s\n", mysqli_connect_error());
			exit();
		}
		$sql = "SELECT photo_file FROM place_photo WHERE place_id = '$place_id' LIMIT 0, 5";
		if($result = $mysqli->query($sql)) {
			if($result->num_rows >= 1) {
				while($row = $result->fetch_array(MYSQLI_ASSOC)) {
					extract($row);
					$array[] = $photo_file;
				}
				return $array;
			} else {
				$array[] = "0";
				return $array;
			}
			$result->close();
		}
		$mysqli->close();
	}
	
	function get_photo($id) {
		include("inc_/sup3rs3cr3tt3xt4m3t0kn0vv.php");
		$mysqli = new mysqli($host, $user, $password, $database);
		if(mysqli_connect_errno()) {
			printf("Connect failed: %s\n", mysqli_connect_error());
			exit();
		}
		$sql = "SELECT photo_file FROM place_photo WHERE photo_id = '$id'";
		if($result = $mysqli->query($sql)) {
			if($result->num_rows >= 1) {
				while($row = $result->fetch_array(MYSQLI_ASSOC)) {
					extract($row);
					return $photo_file;
				}
			}
			$result->close();
		}
		$mysqli->close();
	}
}
?>